import 'dart:io';

import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';

class FlutterFrpc {
  static const methodChannel = MethodChannel('flutter_frpc');
  static Future init({
    required String address,
    required String port,
    required String password,
  }) async {
    String path = "${(await getApplicationSupportDirectory()).path}/frpc.ini";
    File file = File(path);
    if (!file.existsSync()) {
      file.createSync();
    }
    file.writeAsStringSync("""
[common]
server_addr = $address
server_port = $port
token = $password""");
  }

  static Future connect() async {
    await methodChannel.invokeMethod<String>('connect');
  }

  static Future disconnect() async {
    await methodChannel.invokeMethod<String>('disconnect');
  }
}
